From 4d34625f4b0e3250293f8922c4869d3252363608 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 13 Nov 2003 05:28:33 +0000 Subject: [PATCH] Move gpx_entitize to xml_entitize, call from geo.c in at least one of hte cases that we should be calling it (sigh) to correct a problem for Rick outputting URLs with '&' characters in them. --- gpsbabel/defs.h | 1 + gpsbabel/geo.c | 6 +++- gpsbabel/gpx.c | 78 +++++++------------------------------------------ gpsbabel/util.c | 57 ++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 69 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 5e0a025c6..22161ed78 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -338,6 +338,7 @@ char *strsub(char *s, char *search, char *replace); void rtrim(char *s); signed int get_tz_offset(void); const char *get_cache_icon(const waypoint *waypointp); +char * xml_entitize(const char * str); /* * PalmOS records like fixed-point numbers, which should be rounded diff --git a/gpsbabel/geo.c b/gpsbabel/geo.c index aa5f013c0..5a3ddaf37 100644 --- a/gpsbabel/geo.c +++ b/gpsbabel/geo.c @@ -252,6 +252,8 @@ geo_wr_deinit(void) static void geo_waypt_pr(const waypoint *waypointp) { + char *tmp; + fprintf(ofd, "\n"); fprintf(ofd, "", waypointp->shortname); fprintf(ofd, "", waypointp->description); @@ -266,8 +268,10 @@ geo_waypt_pr(const waypoint *waypointp) fprintf(ofd, "%s\n", waypointp->icon_descr); } if (waypointp->url) { + tmp = xml_entitize(waypointp->url); fprintf(ofd, "%s\n", - waypointp->url); + tmp); + free(tmp); } fprintf(ofd, "\n"); } diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 244e60db3..89eeb5af4 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -79,64 +79,6 @@ static route_head *rte_head; #define MYNAME "GPX" #define MY_CBUF 4096 -static -char * gpx_entitize(const char * str) -{ - int elen, ecount; - const char ** ep; - const char * cp; - char * p, * tmp, * xstr; - const char * stdentities[] = { - "&", "&", - "<", "<", - ">", ">", - "'", "'", - "\"", """, - NULL, NULL - }; - ep = stdentities; - elen = ecount = 0; - - /* figure # of entity replacements and additional size. */ - while (*ep) { - cp = str; - while ((cp = strstr(cp, *ep)) != NULL) { - elen += strlen(*(ep + 1)) - strlen(*ep); - ecount++; - cp += strlen(*ep); - } - ep += 2; - } - - /* enough space for the whole string plus entity replacements, if any */ - tmp = xcalloc((strlen(str) + elen + 1), 1); - strcpy(tmp, str); - - /* no entity replacements */ - if (ecount == 0) - return (tmp); - - ep = stdentities; - - while (*ep) { - p = tmp; - while ((p = strstr(p, *ep)) != NULL) { - elen = strlen(*(ep + 1)); - - xstr = xstrdup(p + strlen(*ep)); - - strcpy(p, *(ep + 1)); - strcpy(p + elen, xstr); - - xfree(xstr); - - p += elen; - } - ep += 2; - } - return (tmp); -} - static void tag_gpx(const char **attrv) { @@ -886,7 +828,7 @@ fprint_xml_chain( xml_tag *tag, const waypoint *wpt ) fprint_tag_and_attrs( "<", ">", tag ); if ( tag->cdata ) { - tmp_ent = gpx_entitize( tag->cdata ); + tmp_ent = xml_entitize( tag->cdata ); fprintf( ofd, "%s", tmp_ent ); xfree(tmp_ent); } @@ -900,7 +842,7 @@ fprint_xml_chain( xml_tag *tag, const waypoint *wpt ) } fprintf( ofd, "", tag->tagname); if ( tag->parentcdata ) { - tmp_ent = gpx_entitize(tag->parentcdata); + tmp_ent = xml_entitize(tag->parentcdata); fprintf(ofd, "%s", tmp_ent ); xfree(tmp_ent); } @@ -971,7 +913,7 @@ gpx_waypt_pr(const waypoint *waypointp) gpx_write_time(waypointp->creation_time, "time"); } if (oname) { - tmp_ent = gpx_entitize(oname); + tmp_ent = xml_entitize(oname); fprintf(ofd, "%s\n", tmp_ent); xfree(tmp_ent); } @@ -996,17 +938,17 @@ gpx_waypt_pr(const waypoint *waypointp) waypointp->altitude); } if (waypointp->url) { - tmp_ent = gpx_entitize(waypointp->url); + tmp_ent = xml_entitize(waypointp->url); fprintf(ofd, "%s%s\n", urlbase ? urlbase : "", tmp_ent); xfree(tmp_ent); } if (waypointp->url_link_text) { - tmp_ent = gpx_entitize(waypointp->url_link_text); + tmp_ent = xml_entitize(waypointp->url_link_text); fprintf(ofd, "%s\n", tmp_ent ); xfree(tmp_ent); } if (waypointp->icon_descr) { - tmp_ent = gpx_entitize(waypointp->icon_descr); + tmp_ent = xml_entitize(waypointp->icon_descr); fprintf(ofd, "%s\n", tmp_ent ); xfree(tmp_ent); } @@ -1022,12 +964,12 @@ gpx_track_hdr(const route_head *rte) fprintf(ofd, "\n"); if (rte->rte_name) { - tmp_ent = gpx_entitize(rte->rte_name); + tmp_ent = xml_entitize(rte->rte_name); fprintf(ofd, "%s\n", tmp_ent); xfree(tmp_ent); } if (rte->rte_desc) { - tmp_ent = gpx_entitize(rte->rte_desc); + tmp_ent = xml_entitize(rte->rte_desc); fprintf(ofd, "%s\n", tmp_ent); xfree(tmp_ent); } @@ -1073,12 +1015,12 @@ gpx_route_hdr(const route_head *rte) fprintf(ofd, "\n"); if (rte->rte_name) { - tmp_ent = gpx_entitize(rte->rte_name); + tmp_ent = xml_entitize(rte->rte_name); fprintf(ofd, "%s\n", tmp_ent); xfree(tmp_ent); } if (rte->rte_desc) { - tmp_ent = gpx_entitize(rte->rte_desc); + tmp_ent = xml_entitize(rte->rte_desc); fprintf(ofd, "%s\n", tmp_ent); xfree(tmp_ent); } diff --git a/gpsbabel/util.c b/gpsbabel/util.c index c0e7684eb..3e2e261aa 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -574,3 +574,60 @@ strsub(char *s, char *search, char *replace) strcat(d, p + slen); return d; } + +char * xml_entitize(const char * str) +{ + int elen, ecount; + const char ** ep; + const char * cp; + char * p, * tmp, * xstr; + const char * stdentities[] = { + "&", "&", + "<", "<", + ">", ">", + "'", "'", + "\"", """, + NULL, NULL + }; + ep = stdentities; + elen = ecount = 0; + + /* figure # of entity replacements and additional size. */ + while (*ep) { + cp = str; + while ((cp = strstr(cp, *ep)) != NULL) { + elen += strlen(*(ep + 1)) - strlen(*ep); + ecount++; + cp += strlen(*ep); + } + ep += 2; + } + + /* enough space for the whole string plus entity replacements, if any */ + tmp = xcalloc((strlen(str) + elen + 1), 1); + strcpy(tmp, str); + + /* no entity replacements */ + if (ecount == 0) + return (tmp); + + ep = stdentities; + + while (*ep) { + p = tmp; + while ((p = strstr(p, *ep)) != NULL) { + elen = strlen(*(ep + 1)); + + xstr = xstrdup(p + strlen(*ep)); + + strcpy(p, *(ep + 1)); + strcpy(p + elen, xstr); + + xfree(xstr); + + p += elen; + } + ep += 2; + } + return (tmp); +} -- 2.30.2